package com.hippo.core.utils

import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*

object DateTimeUtils {

    private val formatterMap = mutableMapOf<String, DateFormat>()

    /**
     * 格式化时间戳
     */
    fun format(timeMillis: Long, formatPattern: String = "yyyy-MM-dd HH:mm:ss"): String {
        return formatterMap.getOrPut(formatPattern) {
            SimpleDateFormat(formatPattern, Locale.getDefault())
        }.format(timeMillis)
    }

}